/*
 * @Author: pengfei
 * @Description: 原有H5头部解析
 */
import DealRequest from '../interface/dealRequest.interface';
import unicore from '../core.service';
import core from '../core.service';
import store from '@/store';
export default class OldHeader implements DealRequest{
  encrapt(data:any){
    return {
        'hData':unicore.util.crypto.publicAesEncrypt(data)
    }
  }
  decrapt(res:any,noshowToast?:boolean){
    const data:any = unicore.util.crypto.publicAesDecrypt(res);
    if (data.reqResult.code==-9992) {
      if(unicore.env.isAndksdapp || unicore.env.isIosksdapp){
        /**如果在空手到页面内登录超时 */
        uni.showModal({
          title: "登录超时",
          content:"您已登录超时，请退出当前登录并且重新登录",
          success: res => {
            if (res.confirm) {
              return core.interaction.quit()
            }
          }
        })
      }else{
        /**在H5、微信公众号内登录超时,将跳转页面储存为当前页面，进行跳转 */
        store.state.common.saveUrl = core.dom.window.location.hash.replace(/\#/g,"")
        uni.redirectTo({url:'/pages/login/indexty'})
        return
      }
    }
    if(data.reqResult&&data.reqResult.code!=-60003&&data.reqResult.code!=-200305&&data.reqResult.code<0&&data.reqResult.code!=-200000){ // -200000身份证号码已被认证
        if (noshowToast) {
            return 
        }
        setTimeout(()=>{
            uni.showToast({
                title:data.reqResult.msg,
                icon:'none',
                duration:5000
            })
        },0)
        return;
    }
    return data;
  }
  getHeader(header?:any){
    return Object.assign({},header,{
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8;',
      'X_ClientToken': unicore.config.X_ClientToken,
	    'X_GwApiToken': unicore.config.X_GwApiToken
    })
  }
}